package com.qiumo.gmtool.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ObjectUtil;
import com.qiumo.gmtool.common.RetResult;
import com.qiumo.gmtool.entity.FastBtnEntity;
import com.qiumo.gmtool.mail.MailUtil;
import com.qiumo.gmtool.service.FastBtnService;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * gm功能
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/gm")
public class GmController {

    private final MailUtil mailUtil;

    private final FastBtnService fastBtnService;

    /**
     * 发送原石
     */
    @GetMapping("/sendYs/{num}")
    @SaCheckPermission("money")
    public RetResult sendYs(@PathVariable Integer num) {
        if (num > 9999999) {
            return RetResult.err("数量太大咯~~");
        }
        return mailUtil.sendItem("201", num);
    }

    /**
     * 发送摩拉
     */
    @GetMapping("/sendMl/{num}")
    @SaCheckPermission("money")
    public RetResult sendMl(@PathVariable Integer num) {
        if (num > 9999999) {
            return RetResult.err("数量太大咯~~");
        }
        return mailUtil.sendItem("202", num);
    }

    /**
     * 发送创世结晶
     */
    @GetMapping("/sendCs/{num}")
    @SaCheckPermission("money")
    public RetResult sendCs(@PathVariable Integer num) {
        if (num > 9999999) {
            return RetResult.err("数量太大咯~~");
        }
        return mailUtil.sendItem("203", num);
    }

    /**
     * 发送物品
     */
    @GetMapping("/sendItem")
    @SaCheckPermission("item")
    public RetResult sendItem(@RequestParam Map<String, String> params) {
        if (ObjectUtil.isEmpty(params.get("id"))) {
            return RetResult.err("请选择物品");
        }
        if (ObjectUtil.isEmpty(params.get("num"))) {
            return RetResult.err("请输入数量");
        }
        if (Integer.valueOf(params.get("num")) > 999) {
            return RetResult.err("物品充值数量请勿大于999");
        }
        return mailUtil.sendItem(params.get("id"), Integer.valueOf(params.get("num")));
    }


    /**
     * 发送快捷指令
     */
    @GetMapping("/fastSend/{id}")
    @SaCheckPermission("fast")
    public RetResult fastSend(@PathVariable Integer id) {
        FastBtnEntity btn = fastBtnService.getById(id);
        //没查到或者状态为1都提示不存在即可
        if (ObjectUtil.isEmpty(btn) || btn.getStatus().equals("1")){
            return RetResult.err("指令不存在");
        }
        return mailUtil.fastSend(btn.getMsg());
    }
}
